﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace WinFormsApp1
{
    public partial class Form2 : Form
    {
        private int studentCount = 0; // 用于编号
        private List<Student> students = new List<Student>(); // 用于记录学生对象

        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            if (dataGridView1.Columns.Count < 8)
            {
                dataGridView1.Columns.Clear();
                dataGridView1.Columns.Add("colNumber", "编号");
                dataGridView1.Columns.Add("colName", "姓名");
                dataGridView1.Columns.Add("colId", "学号");
                dataGridView1.Columns.Add("colBirthday", "生日");
                dataGridView1.Columns.Add("colClass", "班级");
                dataGridView1.Columns.Add("colZodiac", "生肖");
                dataGridView1.Columns.Add("colHeightWeight", "身高体重");
                dataGridView1.Columns.Add("colHobby", "爱好");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string name = textBox1.Text.Trim();
            string id = textBox2.Text.Trim();
            string birthday = textBox3.Text.Trim();
            string className = textBox4.Text.Trim();
            string zodiac = textBox5.Text.Trim();
            string heightWeight = textBox6.Text.Trim();
            string hobby = textBox7.Text.Trim();

            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(id) || string.IsNullOrEmpty(birthday)
                || string.IsNullOrEmpty(className) || string.IsNullOrEmpty(zodiac) || string.IsNullOrEmpty(heightWeight))
            {
                MessageBox.Show("请填写所有信息！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            studentCount++;
            Student student = new Student
            {
                Id = long.TryParse(id, out long sid) ? sid : 0,
                Name = name,
                Birthday = birthday,
                ClassName = className,
                Zodiac = zodiac,
                HeightWeight = heightWeight,
                Hobby = hobby // 关键：添加爱好
            };
            students.Add(student);

            int rowIndex = dataGridView1.Rows.Add();
            dataGridView1.Rows[rowIndex].Cells[0].Value = $"学生{studentCount}";
            dataGridView1.Rows[rowIndex].Cells[1].Value = student.Name;
            dataGridView1.Rows[rowIndex].Cells[2].Value = student.Id;
            dataGridView1.Rows[rowIndex].Cells[3].Value = student.Birthday;
            dataGridView1.Rows[rowIndex].Cells[4].Value = student.ClassName;
            dataGridView1.Rows[rowIndex].Cells[5].Value = student.Zodiac;
            dataGridView1.Rows[rowIndex].Cells[6].Value = student.HeightWeight;
            dataGridView1.Rows[rowIndex].Cells[7].Value = student.Hobby; // 关键：显示爱好

            textBox1.Clear();
            textBox2.Clear();
            textBox3.Clear();
            textBox4.Clear();
            textBox5.Clear();
            textBox6.Clear();
            textBox7.Clear();
            textBox1.Focus();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string name = textBox1.Text.Trim();
            string id = textBox2.Text.Trim();
            string birthday = textBox3.Text.Trim();
            string className = textBox4.Text.Trim();
            string zodiac = textBox5.Text.Trim();
            string heightWeight = textBox6.Text.Trim();
            string hobby = textBox7.Text.Trim();

            int rowIndex = dataGridView1.Rows.Add();
            dataGridView1.Rows[rowIndex].Cells[0].Value = $"学生{dataGridView1.Rows.Count}";
            dataGridView1.Rows[rowIndex].Cells[1].Value = name;
            dataGridView1.Rows[rowIndex].Cells[2].Value = id;
            dataGridView1.Rows[rowIndex].Cells[3].Value = birthday;
            dataGridView1.Rows[rowIndex].Cells[4].Value = className;
            dataGridView1.Rows[rowIndex].Cells[5].Value = zodiac;
            dataGridView1.Rows[rowIndex].Cells[6].Value = heightWeight;
            dataGridView1.Rows[rowIndex].Cells[7].Value = hobby;
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}

